local class = reload("class")
local super = reload("super.basic")
local clear = reload("table.opt.clear")
local ifTable = reload("ifTable")

---@class reusable:super.basic @复用仓库
local this = class(super)

---构造
function this:ctor()
    super.ctor(self)
    ---@type any[]
    self._list = {}
end

---申请
---@param narr number|nil @数组预分配
---@param nrec number|nil @哈希预分配
---@return table
function this:get(narr, nrec)
    local list = self._list
    if next(list) then
        return table.remove(list)
    else
        return other.tcreate(narr or 0, nrec or 0)
    end
end

---回收
---@param t table @表
function this:set(t)
    if not ifTable(t) then
        return
    end

    local list = self._list
    if #list > 10000 then
        return
    end
    table.insert(list, clear(t))
end

return this
